Ext.define('JX.Model.Account.Token.Category', {
	extend : 'Ext.data.Model',
	fields : [ 'id', 'name', 'displayLongName' ]
});
Ext.define('JX.Account.Token.Category', {
	singleton : true,

	categorySearchUrl : false,
	chooseCategory : function(callback, scope) {
		var win, selectButton, store, tree;
		store = Ext.create('Ext.data.TreeStore', {
			model : 'JX.Model.Account.Token.Category',
			proxy : {
				type : 'ajax',
				url : this.categorySearchUrl,
				reader : {
					type : 'json'
				}
			},
			root : {
				text : '所有科目',
				id : '0',
				expanded : true
			},
			folderSort : true,
		});
		tree = Ext.create('Ext.tree.Panel', {
			store : store,
			useArrows : true,
			displayField : 'name',
			rootVisible : false,
			listeners : {
				itemclick : {
					fn : function(view, record, item, index, event) {
						selectButton.setDisabled(false);
						selectButton.selectedCategory = record.raw;
					},
					scope : tree
				}
			},
			dockedItems : [ {
				xtype : 'toolbar',
				items : [ {
					text : '全部收起',
					handler : function() {
						tree.collapseAll();
					}
				} ]
			} ]
		});
		selectButton = Ext.widget('button', {
			text : '选择',
			disabled : true,
			selectedModel : null,
			iconCls : 'icon-accept',
			handler : function(button) {
				if (button.selectedCategory) {
					win.close();
					callback.call(scope || this, button.selectedCategory);
				}
			}
		});
		win = Ext.widget('window', {
			title : '选择科目',
			width : 780,
			height : 480,
			modal : true,
			layout : 'fit',
			closable : false,
			buttons : [ selectButton, {
				text : '清除',
				iconCls : 'icon-brick-delete',
				handler : function() {
					win.close();
					callback.call(scope || this, '');
				}
			}, {
				text : '取消',
				iconCls : 'icon-cancel',
				handler : function() {
					win.close();
					// callback.call(scope || this, []);
				}
			} ],
			items : [ tree ]
		});
		win.show();
	}
});